package com.emp.test.springboottest;

import java.util.Date;
import java.util.concurrent.atomic.AtomicInteger;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController//不注解，mapping "/" 会失败
public class App extends SpringBootServletInitializer {

	static private AtomicInteger count = new AtomicInteger(1);
	
    @RequestMapping("/")
    String home() {
    	int i = count.getAndIncrement() % 3;
    	Date now = new Date();
//    	try {
//			Thread.sleep(1000*(80-i*40));
//		} catch (InterruptedException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
        return "Hello World! " + Math.random() + "\n time: " + now + " count : " + i;
    }
    
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(App.class);
    }
    
    public static void main(String[] args) throws Exception {
        SpringApplication.run(App.class, args);
    }

}